'''
@project:pythonProjectT174
@auther:zhongyingjie
@file:tjsp.py
@date:2022/11/5 17:20
@desc:
'''
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
import unittest
class tjsp(unittest.TestCase):
    def setUp(self) -> None:
        self.driver = webdriver.Chrome()  # 创建一个浏览器对象
        self.driver.get('http://192.168.186.111/tinyshop/index.php?con=admin&act=login')
        self.driver.maximize_window()
        self.driver.find_element(By.XPATH,'//input[@name="name"]').send_keys('admin')
        self.driver.find_element(By.XPATH,'//input[@name="password"]').send_keys('123456')
        self.driver.find_element(By.XPATH,'//input[@name="verifyCode"]').send_keys('aaaa')
        self.driver.find_element(By.XPATH,'//input[@value="登 录"]').click()
        self.driver.find_element(By.XPATH,'//a[text()="商品中心"]').click()
        self.driver.find_element(By.XPATH,'//a[@class="icon-plus"]').click()
    def tearDown(self) -> None:
        self.driver.quit()
    def test_zztj(self):
        self.driver.find_element(By.XPATH, '//select[@id="category_id"]').click()
        self.driver.find_element(By.XPATH,'//option[text()="服饰"]').click()
        self.driver.find_element(By.XPATH,'//input[@pattern="required"]').send_keys('服饰1')
        self.driver.find_element(By.XPATH,'//input[@id="goods_no"]').send_keys('334')
        self.driver.find_element(By.XPATH,'//button[@type="button"]').click()
        self.driver.switch_to.frame('Openupimg_dialog')
        self.driver.find_element(By.XPATH,'//li[text()="图库图片"]').click()
        self.driver.find_element(By.XPATH,'//a[text()="下一页"]').click()
        self.driver.find_element(By.XPATH,'//img[@data-src="data/uploads/2014/05/04/6a63f7365e4430b5d07791fd32c66500.jpg"]').click()
        self.driver.find_element(By.XPATH,'//button[text()="保存"]').click()
        self.driver.switch_to.default_content()
        self.driver.find_element(By.XPATH,'//input[@name="pro_no"]').send_keys('334')
        self.driver.find_element(By.XPATH,'//input[@name="store_nums"]').send_keys('99')
        self.driver.find_element(By.XPATH,'//input[@name="weight"]').send_keys('80')
        self.driver.find_element(By.XPATH,'//input[@name="sell_price"]').send_keys('110')
        self.driver.find_element(By.XPATH,'//input[@name="market_price"]').send_keys('120')
        self.driver.find_element(By.XPATH,'//input[@name="cost_price"]').send_keys('100')
        self.driver.find_element(By.XPATH,'//button[@id="open_spec"]').click()
        self.driver.switch_to.frame('Openspec_list')
        self.driver.find_element(By.XPATH,'//a[@href="javascript:;"]').click()
        self.driver.find_element(By.XPATH,'//input[@id="check_all"]').click()
        self.driver.find_element(By.XPATH,'//button[text()="生成所有货品"]').click()
        self.driver.switch_to.default_content()
        self.driver.find_element(By.XPATH,'//input[@value="提交"]').click()
        time.sleep(2)
        a=self.driver.find_element(By.XPATH,'//*[@id="content"]/form/table/tbody/tr[2]/td[3]/a').text
        self.assertIn("服饰",a)
    def test_wfl(self):
        self.driver.find_element(By.XPATH, '//input[@pattern="required"]').send_keys('服饰1')
        self.driver.find_element(By.XPATH, '//input[@id="goods_no"]').send_keys('334')
        self.driver.find_element(By.XPATH, '//button[@type="button"]').click()
        self.driver.switch_to.frame('Openupimg_dialog')
        self.driver.find_element(By.XPATH, '//li[text()="图库图片"]').click()
        self.driver.find_element(By.XPATH, '//a[text()="下一页"]').click()
        self.driver.find_element(By.XPATH, '//img[@data-src="data/uploads/2014/05/04/6a63f7365e4430b5d07791fd32c66500.jpg"]').click()
        self.driver.find_element(By.XPATH, '//button[text()="保存"]').click()
        self.driver.switch_to.default_content()
        self.driver.find_element(By.XPATH, '//input[@name="pro_no"]').send_keys('334')
        self.driver.find_element(By.XPATH, '//input[@name="store_nums"]').send_keys('99')
        self.driver.find_element(By.XPATH, '//input[@name="weight"]').send_keys('80')
        self.driver.find_element(By.XPATH, '//input[@name="sell_price"]').send_keys('110')
        self.driver.find_element(By.XPATH, '//input[@name="market_price"]').send_keys('120')
        self.driver.find_element(By.XPATH, '//input[@name="cost_price"]').send_keys('100')
        self.driver.find_element(By.XPATH, '//button[@id="open_spec"]').click()
        self.driver.switch_to.frame('Openspec_list')
        self.driver.find_element(By.XPATH, '//a[@href="javascript:;"]').click()
        self.driver.find_element(By.XPATH, '//input[@id="check_all"]').click()
        self.driver.find_element(By.XPATH, '//button[text()="生成所有货品"]').click()
        self.driver.switch_to.default_content()
        self.driver.find_element(By.XPATH, '//input[@value="提交"]').click()
        b=self.driver.find_element(By.XPATH,'//*[@id="obj_form"]/div[1]/div[1]/dl[2]/dd/label').text
        self.assertIn('选择分类，若无分类请先创建。',b)
    def test_wmc(self):
        self.driver.find_element(By.XPATH, '//select[@id="category_id"]').click()
        self.driver.find_element(By.XPATH, '//option[text()="服饰"]').click()

        self.driver.find_element(By.XPATH, '//input[@id="goods_no"]').send_keys('334')
        self.driver.find_element(By.XPATH, '//button[@type="button"]').click()
        self.driver.switch_to.frame('Openupimg_dialog')
        self.driver.find_element(By.XPATH, '//li[text()="图库图片"]').click()
        self.driver.find_element(By.XPATH, '//a[text()="下一页"]').click()
        self.driver.find_element(By.XPATH,
                                 '//img[@data-src="data/uploads/2014/05/04/6a63f7365e4430b5d07791fd32c66500.jpg"]').click()
        self.driver.find_element(By.XPATH, '//button[text()="保存"]').click()
        self.driver.switch_to.default_content()
        self.driver.find_element(By.XPATH, '//input[@name="pro_no"]').send_keys('334')
        self.driver.find_element(By.XPATH, '//input[@name="store_nums"]').send_keys('99')
        self.driver.find_element(By.XPATH, '//input[@name="weight"]').send_keys('80')
        self.driver.find_element(By.XPATH, '//input[@name="sell_price"]').send_keys('110')
        self.driver.find_element(By.XPATH, '//input[@name="market_price"]').send_keys('120')
        self.driver.find_element(By.XPATH, '//input[@name="cost_price"]').send_keys('100')
        self.driver.find_element(By.XPATH, '//button[@id="open_spec"]').click()
        self.driver.switch_to.frame('Openspec_list')
        self.driver.find_element(By.XPATH, '//a[@href="javascript:;"]').click()
        self.driver.find_element(By.XPATH, '//input[@id="check_all"]').click()
        self.driver.find_element(By.XPATH, '//button[text()="生成所有货品"]').click()
        self.driver.switch_to.default_content()
        self.driver.find_element(By.XPATH, '//input[@value="提交"]').click()
        c=self.driver.find_element(By.XPATH,'//*[@id="obj_form"]/div[1]/div[1]/dl[5]/dd/label').text
        self.assertIn('不能为空',c)
    def test_wbh(self):
        self.driver.find_element(By.XPATH, '//select[@id="category_id"]').click()
        self.driver.find_element(By.XPATH, '//option[text()="服饰"]').click()
        self.driver.find_element(By.XPATH, '//input[@pattern="required"]').send_keys('服饰1')

        self.driver.find_element(By.XPATH, '//button[@type="button"]').click()
        self.driver.switch_to.frame('Openupimg_dialog')
        self.driver.find_element(By.XPATH, '//li[text()="图库图片"]').click()
        self.driver.find_element(By.XPATH, '//a[text()="下一页"]').click()
        self.driver.find_element(By.XPATH, '//img[@data-src="data/uploads/2014/05/04/6a63f7365e4430b5d07791fd32c66500.jpg"]').click()
        self.driver.find_element(By.XPATH, '//button[text()="保存"]').click()
        self.driver.switch_to.default_content()
        self.driver.find_element(By.XPATH, '//input[@name="pro_no"]').send_keys('334')
        self.driver.find_element(By.XPATH, '//input[@name="store_nums"]').send_keys('99')
        self.driver.find_element(By.XPATH, '//input[@name="weight"]').send_keys('80')
        self.driver.find_element(By.XPATH, '//input[@name="sell_price"]').send_keys('110')
        self.driver.find_element(By.XPATH, '//input[@name="market_price"]').send_keys('120')
        self.driver.find_element(By.XPATH, '//input[@name="cost_price"]').send_keys('100')
        self.driver.find_element(By.XPATH, '//button[@id="open_spec"]').click()
        self.driver.switch_to.frame('Openspec_list')
        self.driver.find_element(By.XPATH, '//a[@href="javascript:;"]').click()
        self.driver.find_element(By.XPATH, '//input[@id="check_all"]').click()
        self.driver.find_element(By.XPATH, '//button[text()="生成所有货品"]').click()
        self.driver.switch_to.default_content()
        self.driver.find_element(By.XPATH, '//input[@value="提交"]').click()
        d=self.driver.find_element(By.XPATH,'//*[@id="obj_form"]/div[1]/div[1]/dl[8]/dd/label').text
        self.assertIn('请输入3个以上的字符(不能为中文)',d)
if __name__=='__main__':
    unittest.main()